package cn.topartip.filters;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Configuration
public class FirstInitFilter01 implements GlobalFilter, Ordered {
    @NacosValue(value="${auth.typeKey}",autoRefreshed = true)
    String authTypeKey;
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

        String auth = exchange.getRequest().getHeaders().getFirst(authTypeKey);
        if (auth != null){
            //如果不空要删除掉
            exchange.getRequest().mutate().header(authTypeKey,"");
        }
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return Ordered.HIGHEST_PRECEDENCE+100;
    }
}
